package cn.com.thinvent.dispatch.service.biz.impl;

import cn.com.thinvent.dispatch.dao.DataCleanAlgorithmMapper;
import cn.com.thinvent.dispatch.entity.DataCleanAlgorithm;
import cn.com.thinvent.dispatch.entity.DataCleanResult;
import cn.com.thinvent.dispatch.entity.ModelFiletag;
import cn.com.thinvent.dispatch.entity.file.filevo;
import cn.com.thinvent.dispatch.entity.response.PagedGridResult;
import cn.com.thinvent.dispatch.service.biz.DataCleanAlgorithmService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Component
public class DataCleanAlgorithmServiceImpl implements DataCleanAlgorithmService {
    @Resource
    private DataCleanAlgorithmMapper dataCleanAlgorithmMapper;

    @Override
    public PagedGridResult<DataCleanAlgorithm> list(DataCleanAlgorithm dataCleanAlgorithm, Integer pageNum, Integer pageSize) {
        PagedGridResult<DataCleanAlgorithm> pagedGridResult = new PagedGridResult<>();
        Integer pageBegin = (pageNum - 1) * pageSize;
        List<DataCleanAlgorithm> list = dataCleanAlgorithmMapper.queryAllByLimit(dataCleanAlgorithm, pageBegin, pageSize);
        Long count = dataCleanAlgorithmMapper.count(dataCleanAlgorithm);
        pagedGridResult.setRows(list);
        pagedGridResult.setRecords(count);
        pagedGridResult.setTotal((Integer.parseInt(count.toString()) + pageSize - 1 )/ pageSize);
        pagedGridResult.setPage(pageNum);
        return pagedGridResult;
    }

    @Override
    public DataCleanAlgorithm saveOrUpdate(DataCleanAlgorithm dataCleanAlgorithm) {
        Date date = new Date();
        if(dataCleanAlgorithm.getId() == null) {
            dataCleanAlgorithm.setCreateTime(date);
            dataCleanAlgorithm.setUpdateTime(date);
            dataCleanAlgorithmMapper.insert(dataCleanAlgorithm);
        } else {
            dataCleanAlgorithm.setUpdateTime(date);
            dataCleanAlgorithmMapper.update(dataCleanAlgorithm);
        }
        return dataCleanAlgorithm;
    }

    @Override
    public Integer delete(Integer id) {
        return dataCleanAlgorithmMapper.deleteById(id);
    }

    @Override
    public DataCleanAlgorithm getById(Integer id) {
        DataCleanAlgorithm dataCleanAlgorithm = dataCleanAlgorithmMapper.queryById(id);
        return dataCleanAlgorithm;
    }
}
